package com.shupian.controller;

import com.shupian.domain.ResponseResult;
import com.shupian.domain.dto.UserAddDto;
import com.shupian.domain.dto.UserUpdateDto;
import com.shupian.domain.entity.User;
import com.shupian.enums.AppHttpCodeEnum;
import com.shupian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import java.util.Objects;

@RestController
@RequestMapping("/system/user")
@Validated
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public ResponseResult getAlluser(Integer pageNum,Integer pageSize,String userName,String phonenumber,String status){
        return userService.getAlluser(pageNum,pageSize,userName,phonenumber,status);
    }
    @PostMapping
    public ResponseResult addUser(@RequestBody UserAddDto userAddDto){
        return userService.addUser(userAddDto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable("id") Long id){
        return userService.removeById(id)
                ? ResponseResult.okResult()
                : ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR);
    }

    @GetMapping("/{id}")
    public ResponseResult getUserById(@PathVariable("id") Long id){
        return userService.getUserById(id);
    }

    @PutMapping
    public ResponseResult updateUser(@RequestBody UserUpdateDto userUpdateDto){
        return userService.updateUser(userUpdateDto);
    }




}
